<?php

namespace App\Console\Commands;

use App\Jobs\ConsultNotify;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;

class ConsultWarn extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'consult:warn';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '咨询时间到期提醒';

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
       $firms =  DB::table('firms')
           ->select(['user.phone','firms.consult_time'])
           ->join('users','firms.user_id','=','users.id')
            ->where('firms.consult_time','<',time())
            ->where('firms.is_warn',1)
             ->get();

       if ($firms->isNotEmpty()){
           foreach ($firms as $firm){
               ConsultNotify::dispatch($firm)->onQueue('consultNotify');
           }
       }



        $brands =  DB::table('firm_brands')
            ->select(['user.phone','firm_brands.consult_time'])
            ->join('users','firm_brands.user_id','=','users.id')
            ->where('firm_brands.consult_time','<',time())
            ->where('firm_brands.is_warn',1)
            ->get();

       if ($brands->isNotEmpty()){
           foreach ($brands as $brand){
               ConsultNotify::dispatch($brand)->onQueue('consultNotify');
           }

       }





        return Command::SUCCESS;
    }

}
